package com.hutao.medical.controller.interceptor;



import org.apache.shiro.authz.UnauthorizedException;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class ExceptionResolver {
	

	
	/**
	 * 权限不足异常
	 * 
	 * @param UnauthorizedException
	 *            exception
	 * @return
	 */
	@ExceptionHandler({ UnauthorizedException.class })
	@ResponseStatus(HttpStatus.OK)
	public ModelAndView processException(UnauthorizedException exception) {
		ModelAndView m = new ModelAndView();
		m.addObject("roncooException", exception.getMessage());
		System.out.println(exception.getMessage());
		m.setViewName("error/unAuthority");
		return m;
	}
	
	/**
	 * 空指针异常
	 * 
	 * @param exception
	 *            exception
	 * @return
	 */
	@ExceptionHandler({ NullPointerException.class })
	@ResponseStatus(HttpStatus.OK)
	public ModelAndView processException(NullPointerException exception) {
		ModelAndView m = new ModelAndView();
		m.addObject("roncooException", exception.getMessage());
		m.setViewName("error/unAuthority");
		return m;
	}
	

	/**
	 *运行时异常处理
	 * 
	 * @param RuntimeException
	 *            exception
	 * @return
	 */
	@ExceptionHandler({ RuntimeException.class })
	@ResponseStatus(HttpStatus.OK)
	public ModelAndView processException(RuntimeException exception) {
		ModelAndView m = new ModelAndView();
		m.addObject("roncooException", exception.getMessage());
		m.setViewName("error/500");
		return m;
	}

	/**
	 * 统一异常处理
	 * 
	 * @param Exception
	 *            exception
	 * @return
	 */
	@ExceptionHandler({ Exception.class })
	@ResponseStatus(HttpStatus.OK)
	public ModelAndView processException(Exception exception) {
		ModelAndView m = new ModelAndView();
		m.addObject("roncooException", exception.getMessage());
		m.setViewName("error/500");
		return m;
	}

}
